﻿namespace DeltaGroup.WheelOfJeopardy.UI.ViewModel
{
    using System.Collections.Generic;

    using DeltaGroup.WheelOfJeopardy.Model;
    using System.ComponentModel;
    using System;

    public class ChallengeModel : BaseViewModel, IDataErrorInfo
    {
        #region Fields

        private string _category;
        private string _expectedResponse;
        private int _index;
        private string _prompt;
        private List<ResponseOption> _responseOptions;
        private List<Synonym> _synonyms;

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ChallengeModel"/> class.
        /// </summary>
        public ChallengeModel()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChallengeModel"/> class.
        /// </summary>
        /// <param name="challenge">The challenge.</param>
        /// <param name="index">The index.</param>
        public ChallengeModel(Challenge challenge, int index)
        {
            _index = index;
            _category = challenge.Category;
            _prompt = challenge.Prompt;
            _expectedResponse = challenge.ExpectedResponse;
            _responseOptions = challenge.ResponseOptionList;
            _synonyms = challenge.SynonymList;
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets or sets the category.
        /// </summary>
        /// <value>The category.</value>
        public string Category
        {
            get { return _category; }
            set
            {
                _category = value;
                FirePropertyChanged("Category");
            }
        }

        /// <summary>
        /// Gets or sets the expected response.
        /// </summary>
        /// <value>The expected response.</value>
        public string ExpectedResponse
        {
            get { return _expectedResponse; }
            set
            {
                _expectedResponse = value;
                FirePropertyChanged("ExpectedResponse");
            }
        }

        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
        public int Index
        {
            get { return _index; }
            set
            {
                _index = value;
                FirePropertyChanged("Index");
            }
        }

        /// <summary>
        /// Gets or sets the point.
        /// </summary>
        /// <value>The point.</value>
        public int Point
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the prompt.
        /// </summary>
        /// <value>The prompt.</value>
        public string Prompt
        {
            get { return _prompt; }
            set
            {
                _prompt = value;
                FirePropertyChanged("Prompt");
            }
        }

        /// <summary>
        /// Gets or sets the response options.
        /// </summary>
        /// <value>The response options.</value>
        public List<ResponseOption> ResponseOptions
        {
            get { return _responseOptions; }
            set
            {
                _responseOptions = value;
                FirePropertyChanged("ResponseOptions");
            }
        }

        /// <summary>
        /// Gets or sets the synonyms.
        /// </summary>
        /// <value>The synonyms.</value>
        public List<Synonym> Synonyms
        {
            get { return _synonyms; }
            set
            {
                _synonyms = value;
                FirePropertyChanged("Synonyms");
            }
        }

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <value></value>
        /// <returns>An error message indicating what is wrong with this object. The default is an empty string ("").</returns>
        public string Error
        {
            get { return null; }
        }

        #endregion Properties

        #region IDataErrorInfo Members

        public string this[string columnName]
        {
            get 
            {
                if(columnName == "Prompt")
                {
                    if (String.IsNullOrWhiteSpace(Prompt))
                        return "Please provide the prompt"; 
                }
                else if(columnName == "ExpectedResponse")
                {
                    if (String.IsNullOrWhiteSpace(ExpectedResponse))
                        return "Please provide the expected response"; 
                }
                return null;
            }
        }

        #endregion
    }
}